﻿using KAKA.Domain;
using KAKA.Repository;
using Morus;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace KAKA.Service
{
    public class MessageService
    {
        public IMessageRepository MessageRepository { get; private set; }

        public MessageService()
        {
            MessageRepository = IoC.Resolve<IMessageRepository>();
        }

        public void SendMessage(User sender, User receiver, Guid appetizerId)
        {
            using (var uow = UnitOfWork.Begin())
            {
                var appetizer = MessageRepository.GetAppetizer(appetizerId);
                var message = Message.Create(appetizer.Subject, appetizer.Content, sender);

                message.Notify(receiver);
                MessageRepository.Add(message);

                uow.Commit();
            }
        }
    }
}
